package com.yanqu.road.server.cmd.chefduel.process3.cross;

import com.yanqu.road.entity.log.chefduel.LogChefDuel3Join;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_CHEF_DUEL3_JOIN_JOINER, desc = "跨服参加者返回加奖励")
public class CrossJoinBanquetJoinerCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ChefDuelProto.CrossChefDuel3JoinBanquetMsg crossRespMsg = ChefDuelProto.CrossChefDuel3JoinBanquetMsg.parseFrom(packet.getBytes());
		ret = crossRespMsg.getRet();
		GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(crossRespMsg.getJoinerUserId());
		if(gamePlayer == null){
			log.error("厨神3:"+packet.getPlayerId()+"{消息返回玩家无了}");
			return;
		}
		ChefDuelProto.ChefDuel3JoinBanquetRespMsg.Builder respMsg = ChefDuelProto.ChefDuel3JoinBanquetRespMsg.newBuilder();
		if(ret == 0){
			String reward = ChefDuelMgr.chefDuel3joinerBackMsg(crossRespMsg.getActivityId(),crossRespMsg.getJoinerUserId(),crossRespMsg.getBanquetItemId());
			respMsg.setReward(reward);

			AutoLogMgr.add(new LogChefDuel3Join(crossRespMsg.getActivityId(),
					crossRespMsg.getJoinerUserId(),
					crossRespMsg.getHomeUserId(),
					crossRespMsg.getOpenCampId(),
					crossRespMsg.getTimes(),
					reward,
					crossRespMsg.getIntegral()));
		}
		respMsg.setRet(ret);
		gamePlayer.sendPacket(Protocol.U_CHEF_DUEL3_JOIN_BANQUET, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
